package com.baichang.taoshunda.utils;

import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.utils.rongyun.RongCloud;
import com.baichang.taoshunda.utils.rongyun.models.CodeSuccessResult;
import com.baichang.taoshunda.utils.rongyun.models.TokenResult;
import com.baichang.taoshunda.utils.rongyun.models.UserInfo;

public class RongYunUtils {

    static String appKey = "uwd1c0sxupe41";//替换成您的appkey
    static String appSecret = "DHtkKzb1uI";//替换成匹配上面key的secret

    static RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);


    public static String getRYToken(String userId, String userName, String headPic) throws ServiceException {
        // 获取 Token 方法
        TokenResult userGetTokenResult = null;
        try {
            userGetTokenResult = rongCloud.user.getToken(userId, userName, headPic);
        } catch (Exception e) {
            throw new ServiceException("获取用户token失败");
        }
//        System.out.println("getToken:  " + userGetTokenResult.toString());
        return userGetTokenResult.toString();
    }

    public static String refreshInfo(String userId, String userName, String headPic) throws ServiceException {
        // 获取 Token 方法
        CodeSuccessResult userGetTokenResult = null;
        try {
            userGetTokenResult = rongCloud.user.refresh(userId, userName, headPic);
        } catch (Exception e) {
            throw new ServiceException("获取用户token失败");
        }
//        System.out.println("getToken:  " + userGetTokenResult.toString());
        return userGetTokenResult.toString();
    }

    public static String getUserInfo(String userId) throws ServiceException {
        // 获取 Token 方法
        UserInfo userGetTokenResult = null;
        try {
            userGetTokenResult = rongCloud.user.userInfo(userId);
        } catch (Exception e) {
            throw new ServiceException("获取用户token失败");
        }
//        System.out.println("getToken:  " + userGetTokenResult.toString());
        return userGetTokenResult.toString();
    }

    public static void main(String[] args) throws ServiceException {
        System.out.print(getUserInfo("user14"));
    }
}
